window.onload = function () {

    calOrder()          //计算购物订单相关金额信息
    // initData()
}

function calOrder() {
    var trs = myTableProduct.getElementsByTagName('tr')
    var sum = 0
    var totalNum = 0
    for (var i = 1; i < trs.length; i++) {
        var price = trs[i].children[3].firstElementChild.innerHTML
        var num = trs[i].children[4].firstElementChild.value
        totalNum += parseInt(num)
        sum += price * num
    }
    product_total.innerHTML = sum.toFixed(2)
    product_mun.innerHTML = totalNum
}

function del(obj) {
    if (confirm('您确定要删除吗？')) {
        obj.parentNode.parentNode.parentNode.removeChild(obj.parentNode.parentNode) //删除行节点
        calOrder()   //更新数据
    }
}
$(function () {

    $(".all").click(function () {
        $(".sonCheck").prop("checked", this.checked);
    });

    $('.cut').click(function () {
        if ($('.sonCheck:checked').length > 0) {
            if (confirm("确认要删除吗?")) {
                $('.sonCheck:checked').parent().parent().remove()
            }
        } else {
            alert('未选中商品！')
        }
    })


    $(".btn-primary").click(function () {
        window.location.href = "placeOrder.html"
    });

    $("#btnOrder").click(function () {
        var name = document.querySelector('.bName').innerText
        var author = document.querySelector('.bAuthor').innerText
        var price = document.querySelector('.bPrice').innerText
        var num = document.querySelector('.bNum').value
        sessionStorage.setItem('bookInformation', JSON.stringify({ 'bName': name, 'bAuthor': author, 'bPrice': price, 'bNum': num }))
        if (confirm('挑选好了吗？')) {
            window.location.href = "placeOrder.html"
        }
    })
})